package com.hm.kafkademo.controller;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hm.kafkademo.dto.Camera;
import com.hm.kafkademo.mapper.CameraMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/camera")
public class ProducerDemoController1 {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    private CameraMapper cameraMapper;

    @GetMapping("/list")
    public String listAll(){
        List<Camera> cameras = cameraMapper.selectList(null);
        return JSON.toJSONString(cameras);
    }

    @GetMapping()
    public List<Camera> getCameraListByIndexCode(@RequestParam String indexCode) {
        QueryWrapper<Camera> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("index_code", indexCode);
        List<Camera> cameraList = cameraMapper.selectList(queryWrapper);
        return cameraList;
    }

}